﻿<controls:MetroWindow x:Class="Restaurant.Reservations.View.NewReservation"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
                      xmlns:system="clr-namespace:System;assembly=mscorlib"
                      xmlns:validation="clr-namespace:Restaurant.Reservations.ValidationRules"
                      x:Name="NewReservationMetroWindow"
                      Title="New Reservation"
                      Width="700"
                      Height="250"
                      BorderBrush="Black"
                      BorderThickness="1"
                      ResizeMode="NoResize"
                      ShowCloseButton="False"
                      ShowInTaskbar="False"
                      WindowStartupLocation="CenterOwner"
                      WindowStyle="ToolWindow">
    <controls:MetroWindow.Resources>
        <system:String x:Key="ContactRegExPattern">\(?\d{3}\)?-? *\d{3}-? *-?\d{4}</system:String>
    </controls:MetroWindow.Resources>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="150" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <GroupBox Grid.Row="0"
                  Grid.Column="0"
                  Margin="5"
                  Header="Select Tables">
            <ItemsControl x:Name="TableItemsControl" ItemsSource="{Binding TablesAvaialble}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Margin="0,2,0,0"
                                  Command="{Binding DataContext.SelectingTableCommand,
                                                    ElementName=TableItemsControl}"
                                  CommandParameter="{Binding .}"
                                  IsChecked="{Binding IsSelected}">
                            <CheckBox.Content>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Table:" />
                                    <TextBlock Text="{Binding TableNumber}" />
                                    <TextBlock Text="(" />
                                    <TextBlock Text="{Binding MaxOccupancy}" />
                                    <TextBlock Text=")" />
                                </StackPanel>
                            </CheckBox.Content>
                        </CheckBox>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </GroupBox>
        <GroupBox Grid.Row="0"
                  Grid.Column="1"
                  Grid.ColumnSpan="3"
                  HorizontalAlignment="Stretch"
                  Header="Cutomer Details">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition MinWidth="150" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0"
                           Grid.Column="0"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Customer Name" />

                <TextBlock Grid.Row="0"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="CustomerNameTextBox"
                         Grid.Row="0"
                         Grid.Column="2"
                         MinWidth="140"
                         Margin="5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center">
                    <TextBox.Text>
                        <Binding Path="CustomerName" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <validation:RegexValidationRule ErrorMessage="Letters only." Pattern="[\p{L} ]+$" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>

                <TextBlock Grid.Row="0"
                           Grid.Column="3"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Contact" />
                <TextBlock Grid.Row="0"
                           Grid.Column="4"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="ContactNumberTextBox"
                         Grid.Row="0"
                         Grid.Column="5"
                         MinWidth="140"
                         Margin="5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center">
                    <TextBox.Text>
                        <Binding Path="ContactNumber" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <validation:RegexValidationRule ErrorMessage="10 digit phone no. required." Pattern="{StaticResource ContactRegExPattern}" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>

                <TextBlock Grid.Row="1"
                           Grid.Column="0"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Selected Tables" />
                <TextBlock Grid.Row="1"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBlock x:Name="TableSelectedTextBlock"
                           Grid.Row="1"
                           Grid.Column="2"
                           Margin="5"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Center"
                           FontWeight="Bold"
                           Text="{Binding SelectedTableString,
                                          TargetNullValue='No Table Selected'}" />

                <TextBlock Grid.Row="1"
                           Grid.Column="3"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Occupants" />
                <TextBlock Grid.Row="1"
                           Grid.Column="4"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text=":" />

                <StackPanel Grid.Row="1"
                            Grid.Column="5"
                            Margin="5"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <controls:NumericUpDown Interval="1"
                                            IsReadOnly="True"
                                            Minimum="0"
                                            Value="{Binding Occupants}" />
                    <TextBlock Margin="5,0,0,0"
                               VerticalAlignment="Center"
                               FontWeight="Bold"
                               Text="( Max.:" />
                    <TextBlock Margin="2,0,0,0"
                               VerticalAlignment="Center"
                               FontWeight="Bold"
                               Text="{Binding MaxOccupancy}" />
                    <TextBlock Margin="2,0,0,0"
                               VerticalAlignment="Center"
                               FontWeight="Bold"
                               Text=" )" />
                </StackPanel>


                <TextBlock Grid.Row="2"
                           Grid.Column="0"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Checkin-Date" />
                <TextBlock Grid.Row="2"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text=":" />
                <DatePicker x:Name="ReservationDatePicker"
                            Grid.Row="2"
                            Grid.Column="2"
                            Margin="5"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            DisplayDateEnd="{Binding EndDate}"
                            DisplayDateStart="{Binding StartDate}"
                            SelectedDate="{Binding SelectedDate}" />


                <TextBlock Grid.Row="2"
                           Grid.Column="3"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text="Checkin-Time" />
                <TextBlock Grid.Row="2"
                           Grid.Column="4"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text=":" />
                <!--<userControls:ucDateTimeUpDown x:Name="TimePicker"
                                           Grid.Row="2"
                                           Grid.Column="5"
                                           Height="33"
                                           Margin="5"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           SelectedTime="{Binding CheckInTime,
                                                                  Mode=TwoWay,
                                                                  UpdateSourceTrigger=PropertyChanged}" />-->
                <Grid Grid.Row="2"
                      Grid.Column="5"
                      Height="33"
                      Margin="5">
                    <Border BorderBrush="Black" BorderThickness=".25" />
                    <StackPanel Orientation="Horizontal">


                        <TextBlock x:Name="AddHoursTextBox"
                                   MinWidth="20"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="{Binding DisplayTimeHours,
                                                  Mode=OneWay}"
                                   TextAlignment="Center" />
                        <StackPanel Margin="0,0,0,-8"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Orientation="Vertical">
                            <Button x:Name="HourUpButton"
                                    Command="{Binding AddHoursCommand}"
                                    CommandParameter="1">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border BorderBrush="Black" BorderThickness=".25">
                                            <Viewbox Width="10" Height="10">
                                                <Image Source="{StaticResource UpImage}" />
                                            </Viewbox>
                                        </Border>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.ToolTip>
                                    <ToolTip Content="Press to increase time with 1 hour." Style="{StaticResource GenericToolTipStyle}" />
                                </Button.ToolTip>
                            </Button>

                            <Button x:Name="HourDownButton"
                                    Margin="0,-8,0,0"
                                    Command="{Binding AddHoursCommand}"
                                    CommandParameter="0">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border BorderBrush="Black" BorderThickness=".25">
                                            <Viewbox Width="10" Height="10">
                                                <Image Source="{StaticResource DownImage}" />
                                            </Viewbox>
                                        </Border>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.ToolTip>
                                    <ToolTip Content="Press to decrease time with 1 hour." Style="{StaticResource GenericToolTipStyle}" />
                                </Button.ToolTip>
                            </Button>
                        </StackPanel>
                        <TextBlock Margin="3,0,0,0"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="h." />
                        <TextBlock Margin="3,0,0,0"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text=":"
                                   TextAlignment="Center" />
                        <TextBlock x:Name="AddMinutesTextBox"
                                   MinWidth="20"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="{Binding DisplayTimeMinutes,
                                                  Mode=OneWay}"
                                   TextAlignment="Center" />


                        <StackPanel Margin="0,0,0,-8"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Orientation="Vertical">
                            <Button x:Name="MinutesUpButton"
                                    Command="{Binding AddMinutesCommand}"
                                    CommandParameter="1">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border BorderBrush="Black" BorderThickness=".25">
                                            <Viewbox Width="10" Height="10">
                                                <Image Source="{StaticResource UpImage}" />
                                            </Viewbox>
                                        </Border>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.ToolTip>
                                    <ToolTip Content="Press to increase time with 15 minutes" Style="{StaticResource GenericToolTipStyle}" />
                                </Button.ToolTip>
                            </Button>

                            <Button x:Name="MinutesDownButton"
                                    Margin="0,-8,0,0"
                                    Command="{Binding AddMinutesCommand}"
                                    CommandParameter="0">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border BorderBrush="Black" BorderThickness="0.25">
                                            <Viewbox Width="10" Height="10">
                                                <Image Source="{StaticResource DownImage}" />
                                            </Viewbox>
                                        </Border>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.ToolTip>
                                    <ToolTip Content="Press to decrease time with 15 minutes" Style="{StaticResource GenericToolTipStyle}" />
                                </Button.ToolTip>
                            </Button>
                        </StackPanel>
                        <TextBlock Margin="3,0,3,0"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="m." />

                        <ComboBox x:Name="AmPmComboBox"
                                  MinWidth="45"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  BorderThickness=".25"
                                  ItemsSource="{Binding AmPmTypes}"
                                  SelectedItem="{Binding DisplayAmPm}" />
                    </StackPanel>


                </Grid>

            </Grid>
        </GroupBox>
        <Separator Grid.Row="1"
                   Grid.Column="0"
                   Grid.ColumnSpan="4" />
        <Button Grid.Row="2"
                Grid.Column="2"
                Width="50"
                Margin="5"
                HorizontalAlignment="Right"
                VerticalAlignment="Center"
                Command="{Binding SaveCommand}"
                Content="Save">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="IsEnabled" Value="False" />
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=ContactNumberTextBox}" Value="False" />
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=CustomerNameTextBox}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="IsEnabled" Value="True" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
        <Button Grid.Row="2"
                Grid.Column="3"
                Width="50"
                Margin="0,5,5,5"
                HorizontalAlignment="Right"
                VerticalAlignment="Center"
                Command="{Binding CancelCommand}"
                Content="Cancel" />
    </Grid>
</controls:MetroWindow>